package main

import (
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/service"
	"im_sys/apps/task/mq/internal/config"
	"im_sys/apps/task/mq/internal/handler"
	"im_sys/apps/task/mq/internal/svc"
)

var configFile = flag.String("f", "etc/dev/task.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	if err := c.SetUp(); err != nil {
		panic(err)
	}

	ctx := svc.NewServiceContext(c)

	// 创建一个Listener对象
	listener := handler.NewListener(ctx)

	// ServiceGroup是go-zero用于管理多个服务实例的生命周期的结构，此处用于管理Listener中定义的所有服务（目前只包含消费者拉取）
	serviceGroup := service.NewServiceGroup()
	for _, s := range listener.Services() {
		serviceGroup.Add(s)
	}

	fmt.Println("start task mq server at ", c.ListenOn, "......")
	serviceGroup.Start()
}
